namespace webapi_day4 {

    // 计算两个日期之间的天数差

    function getDaysBetweenDates(date1: string, date2: string) {
        const startDate: Date = new Date(date1);
        const endDate: Date = new Date(date2);
        const timeDifference: number = endDate.getTime() - startDate.getTime();  // 两个日期相差的毫秒数
        const daysDifference: number = timeDifference / (1000 * 3600 * 24); // 相差的天数
        // 1000=>1s * 3600=>1h * 24=>1天
        return Math.abs(Math.ceil(daysDifference)); // Math.ceil()向上取整  Math.abs() 绝对值
    }

    // 示例用法
    console.log(getDaysBetweenDates('2024-08-01', '2024-08-14')); // 输出: 13

}